{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "import cv2\r\n",
    "cap = cv2.VideoCapture(\"1.mp4\")\r\n",
    "isOpened = cap.isOpened\r\n",
    "print(isOpened)\r\n",
    "fps = cap.get(cv2.CAP_PROP_FPS)\r\n",
    "width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))\r\n",
    "height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))\r\n",
    "print(fps,width,height)\r\n",
    "i=0\r\n",
    "while(isOpened):\r\n",
    "    if i==10:\r\n",
    "        break\r\n",
    "    else:\r\n",
    "        i=i+1\r\n",
    "    (flag,frame) = cap.read()\r\n",
    "    fileName = 'image'+str(i)+'.jpg'\r\n",
    "    print(fileName)\r\n",
    "    if flag:\r\n",
    "        cv2.imwrite(fileName,frame,[cv2.IMWRITE_JPEG_QUALITY])\r\n",
    "print('end!')"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "<built-in method isOpened of cv2.VideoCapture object at 0x000001E73B4802D0>\n",
      "29.008016032064127 540 960\n",
      "image1.jpg\n",
      "image2.jpg\n",
      "image3.jpg\n",
      "image4.jpg\n",
      "image5.jpg\n",
      "image6.jpg\n",
      "image7.jpg\n",
      "image8.jpg\n",
      "image9.jpg\n",
      "image10.jpg\n",
      "end!\n"
     ]
    }
   ],
   "metadata": {
    "scrolled": true
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "图片合成视频"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "import cv2\r\n",
    "img = cv2.imread('image1.jpg')\r\n",
    "imgInfo = img.shape\r\n",
    "size = (imgInfo[1],imgInfo[0])\r\n",
    "print(size)\r\n",
    "videoWrite=cv2.VideoWriter('2.mp4',-1,5,size)#1.filename2.编码器3帧率4size\r\n",
    "for i in range(1,11):\r\n",
    "    fileName = 'image{0}{1}'.format(i,'.jpg')\r\n",
    "    img = cv2.imread(fileName)\r\n",
    "    videoWrite.write(img)\r\n",
    "print('end!')"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "(540, 960)\n",
      "end!\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [],
   "outputs": [],
   "metadata": {}
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.8.8 64-bit ('base': conda)"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "interpreter": {
   "hash": "73e03da126b73bfff3642ec5261d56fa25c444ea595de51041687efaa60dda41"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}